﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EasyUIMvc.Tree;
using Newtonsoft.Json;
using EasyUIMvc;

namespace EasyUIMvc.Samples.Controllers
{
    public class SampleController : Controller
    {
        //
        // GET: /Sample/

        public ActionResult Index()
        {
            return View();
        }

        #region "Menu Button"
        public ActionResult Menu()
        {
            var menuList = new List<MenuItem>
                           {
                                new MenuItem("menu1"),
                                new MenuItem("menu2")
                                {
                                    Childs=new List<MenuItem>
                                            {
                                                new MenuItem("menu3"),
                                                new MenuItem("menu4")
                                            }
                                }
                            };
            return View(menuList);
        }
        public ActionResult LinkButton()
        {
            return View();
        }
        public ActionResult MenuButton()
        {
            var menuList = new List<MenuItem>();
            var menu1 = new MenuItem("menu1");
            var menu2 = new MenuItem("menu2");
            var menu3 = new MenuItem("menu3");
            var menu4 = new MenuItem("menu4");
            menu2.Childs.Add(menu3);
            menu2.Childs.Add(menu4);
            menuList.Add(menu1);
            menuList.Add(menu2);
            return View(menuList);
        }
        #endregion

        #region "Form"

        public ActionResult ComboBox() {
            return View();
        }
        public ActionResult Calendar()
        {
            return View();
        }

        #endregion

        #region "Window"

        public ActionResult Window()
        {
            return View();
        }

        public ActionResult WindowBase()
        {
            return View();
        }

        public ActionResult Accordion()
        {
            return View();
        }

        public ActionResult DialogToolbar()
        {
            return View();
        }
        public ActionResult ComboGrid()
        {
            return View();
        }

        public ActionResult MultipleComboTree()
        {
            return View();
        }

        public ActionResult TreeGrid()
        {
            return View();
        }

        public ActionResult TooltipHoverText()
        {
            return View();
        }

        public ActionResult TooltipHoverLink()
        {
            return View();
        }

        public ActionResult NumberBox()
        {
            return View();
        }

        public ActionResult Messager()
        {
            return View();
        }

        #endregion

        #region " DataGird Tree"

        public ActionResult DataGrid() {
            return View();
        }
        public ActionResult Tree()
        {
            return View();
        }

        #endregion

        public ActionResult Test() {
            var menuList = new List<MenuItem>(){
                new MenuItem("menu1"),
                new MenuItem("menu2"){
                    Childs=new List<MenuItem>(){
                        new MenuItem("menu3"),
                        new MenuItem("menu4")
                    }
                }
            };
            return View(menuList);
        }
        public JsonResult GetJson() {
            var jnlist = new List<JsonNode>();
            var jn1 = new JsonNode() { Id = "1", Name = "LY", Amount=4000000, Desc ="Thu tiền nộp ngân sách nhà nước", Age = "18" };
            var jn2 = new JsonNode { Id = "2", Name = "YYY", Age = "17" };
            var jn3 = new JsonNode { Id = "3", Name = "test", Age = "12" };
            var jn4 = new JsonNode() { Id = "1", Name = "LY", Amount = 4000000, Desc = "Thu tiền nộp ngân sách nhà nước", Age = "18" };
            var jn5 = new JsonNode() { Id = "1", Name = "LY", Amount = 4000000, Desc = "Thu tiền nộp ngân sách nhà nước", Age = "18" };
            var jn6 = new JsonNode() { Id = "1", Name = "LY", Amount = 4000000, Desc = "Thu tiền nộp ngân sách nhà nước", Age = "18" };
            var jn7 = new JsonNode() { Id = "1", Name = "LY", Amount = 4000000, Desc = "Thu tiền nộp ngân sách nhà nước", Age = "18" };
            var jn8 = new JsonNode() { Id = "1", Name = "LY", Amount = 4000000, Desc = "Thu tiền nộp ngân sách nhà nước", Age = "18" };
            var jn9 = new JsonNode() { Id = "1", Name = "LY", Amount = 4000000, Desc = "Thu tiền nộp ngân sách nhà nước", Age = "18" };
            var jn10 = new JsonNode() { Id = "1", Name = "LY", Amount = 4000000, Desc = "Thu tiền nộp ngân sách nhà nước", Age = "18" };
            var jn11 = new JsonNode() { Id = "1", Name = "LY", Amount = 4000000, Desc = "Thu tiền nộp ngân sách nhà nước", Age = "18" };
            var jn12 = new JsonNode() { Id = "1", Name = "LY", Amount = 4000000, Desc = "Thu tiền nộp ngân sách nhà nước", Age = "18" };
            var jn13 = new JsonNode() { Id = "1", Name = "LY", Amount = 4000000, Desc = "Thu tiền nộp ngân sách nhà nước", Age = "18" };
            var jn14 = new JsonNode() { Id = "1", Name = "LY", Amount = 4000000, Desc = "Thu tiền nộp ngân sách nhà nước", Age = "18" };
            var jn15 = new JsonNode() { Id = "1", Name = "LY", Amount = 4000000, Desc = "Thu tiền nộp ngân sách nhà nước", Age = "18" };
            var jn16 = new JsonNode() { Id = "1", Name = "LY", Amount = 4000000, Desc = "Thu tiền nộp ngân sách nhà nước", Age = "18" };
            var jn17 = new JsonNode() { Id = "1", Name = "LY", Amount = 4000000, Desc = "Thu tiền nộp ngân sách nhà nước", Age = "18" };
            var jn18 = new JsonNode() { Id = "1", Name = "LY", Amount = 4000000, Desc = "Thu tiền nộp ngân sách nhà nước", Age = "18" };
            var jn19 = new JsonNode() { Id = "1", Name = "LY", Amount = 4000000, Desc = "Thu tiền nộp ngân sách nhà nước", Age = "18" };
            jnlist.Add(jn1);
            jnlist.Add(jn2);
            jnlist.Add(jn3);
            jnlist.Add(jn4);
            jnlist.Add(jn5);
            jnlist.Add(jn6);
            jnlist.Add(jn7);
            jnlist.Add(jn8);
            jnlist.Add(jn9);
            jnlist.Add(jn10);
            jnlist.Add(jn11);
            jnlist.Add(jn12);
            jnlist.Add(jn13);
            jnlist.Add(jn14);
            jnlist.Add(jn15);
            jnlist.Add(jn16);
            jnlist.Add(jn17);
            jnlist.Add(jn18);
            jnlist.Add(jn19);

            return Json(jnlist);
            //return JsonConvert.SerializeObject(jnlist, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
        }
        public JsonResult TreeData()
        {
            var list = new List<TreeNode>
                       { 
                            new TreeNode
                            {
                                text = "Node 1",
                                Id = "1",
                                state="open"
                            },
                            new TreeNode
                            {
                                text = "Node 2",
                                Id = "2",
                                state = "closed",
                                children = new List<TreeNode>
                                            {
                                                new TreeNode
                                                {
                                                    text="Node con 1",
                                                    Id="21",
                                                    state="open"
                                                },
                                                new TreeNode
                                                {
                                                    text="Node con 2",
                                                    Id="22",
                                                    state="open"
                                                }
                                }
                            }
            };
            return Json(list);
            //return JsonConvert.SerializeObject(list, Formatting.Indented, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
        }
    }
    public class JsonNode {
        public string Id { get; set; }
        public string Name { get; set; }
        public decimal Amount { get; set; }
        public string Desc { get; set; }
        public string Age { get; set; }
    }
}
